<template>
  <el-dialog
    title="库存明细"
    :visible.sync="visible"
    width="80%"
    :before-close="
      () => {
        $emit('close');
      }
    "
  >
    <el-row>
      <el-col :span="10">
        <span>检索日期</span>
      </el-col>
      <el-col style="text-align:right;" :span="14">
        <el-date-picker
          v-model="timeRange"
          type="daterange"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd HH:mm:ss"
          :default-time="['00:00:00', '23:59:59']"
          size="small"
        >
        </el-date-picker>
      </el-col>
    </el-row>
    <el-table
      :data="detailList"
      style="width: 100%;margin-top:5px;"
      :height="500"
      border
      stripe
    >
      <el-table-column label="时间" prop="created_at"> </el-table-column>
      <el-table-column label="类型">
        <template slot-scope="scope">
          <div>{{ scope.row.spu_type === 1 ? "入库" : "出库" }}</div>
        </template>
      </el-table-column>
      <el-table-column label="数量" prop="number"> </el-table-column>
      <el-table-column label="操作人" prop="admin"> </el-table-column>
      <el-table-column label="备注" prop="spu_message"> </el-table-column>
    </el-table>
    <div class="table-bottom-bar">
      <div></div>
      <el-pagination
        @current-change="handleCurrentChange"
        :current-page.sync="page"
        :page-size="size"
        layout="total, prev, pager, next"
        :total="total"
        :background="true"
      >
      </el-pagination>
    </div>
  </el-dialog>
</template>

<script>
import { getInventoryDetail } from "@/api/good-mng";
export default {
  props: ["visible", "id"],
  data() {
    return {
      timeRange: [],
      total: 0,
      size: 0,
      page: 1,
      detailList: []
    };
  },
  watch: {
    visible: function(val) {
      if (val) {
        this.getInventoryDetail(1);
      } else {
      }
    },
    timeRange: function(val) {
      this.getInventoryDetail(1);
    }
  },
  methods: {
    handleCurrentChange(page) {
      this.getInventoryList(page, this.tabName);
    },
    getInventoryDetail(page) {
      getInventoryDetail({
        id: this.id,
        page,
        start_time: this.timeRange && this.timeRange.length ? this.timeRange[0] : null,
        end_time: this.timeRange && this.timeRange.length ? this.timeRange[1] : null
      }).then(res => {
        if (res.code === 200) {
          this.total = res.data.total;
          this.size = res.data.per_page;
          this.detailList = res.data.data;
        }
      });
    }
  },
  created() {}
};
</script>

<style>
</style>
